package cn.domain;
/**
 * 用户实体
 */

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

public class User implements Serializable {
    private Long id;
    private String userName;//用户登录名
    private String name;//用户姓名
    private String password;//用户密码
    private Department Department;//用户所在的部门
    private String Sex;//用户性别
    private String phone;//用户手机号
    private String email;//用户邮箱
    private String descriptment;//说明
    private Set<Role> role = new HashSet<Role>();//用户对应的岗位

    //系统管理
    public boolean booleanPrivilege(String name) {
        //判断如果登录用户是超级管理员，直接返回true
        if (userName.equals("admin")) {
            return true;
        }
        for (Role roles : role) {
            Set<Privilege> privileges = roles.getPrivileges();
            for (Privilege privilege : privileges) {
                if (privilege.getName().equals(name)) {
                    return true;
                }

            }
        }
        return false;
    }

    public boolean booleanUrl(String url) {
        //判断如果登录用户是超级管理员，直接返回true
        if (userName.equals("admin")) {
            return true;
        }
        for (Role roles : role) {
            Set<Privilege> privileges = roles.getPrivileges();
            for (Privilege privilege : privileges) {
                if (url.equals(privilege.getUrl())) {
                    return true;
                }

            }
        }
        return false;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public cn.domain.Department getDepartment() {
        return Department;
    }

    public void setDepartment(cn.domain.Department department) {
        Department = department;
    }

    public String getSex() {
        return Sex;
    }

    public void setSex(String sex) {
        Sex = sex;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getDescriptment() {
        return descriptment;
    }

    public void setDescriptment(String descriptment) {
        this.descriptment = descriptment;
    }

    public Set<Role> getRole() {
        return role;
    }

    public void setRole(Set<Role> role) {
        this.role = role;
    }
}
